package cn.com.dhcc.turbo.dao.registry;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import cn.com.dhcc.app.core.CM;
import cn.com.dhcc.app.core.dao.AbstractCrudDao;
import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.turbo.entity.registry.PriorityConf;
import cn.com.dhcc.turbo.entity.registry.wapper.PriorityConfRowWapper;
@Repository
public class PriorityConfDao extends AbstractCrudDao<PriorityConf> {
	@SuppressWarnings("deprecation")
	private static Logger logger = Log.getExistLogger(LOGTYPE.TURBO);

	/**
	 * 获取权限优先级配置
	 * 
	 * @param ownId
	 *            对象id
	 * @return
	 * @throws DaoException
	 */
	public PriorityConf getByOwnId(String ownId) throws DaoException {
		final String sql = "select * from " + SI_TABLE("turbo_priority_conf")
				+ " where own_id=?";
		String msg = "";
		try {
			return CM.getDao().get("获取权限优先级配置", sql,
					new PriorityConfRowWapper(), new Object[] { ownId });
		} catch (DaoException e) {
			msg = "获取权限优先级配置失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}

	/**
	 * 修改权限优先级配置
	 * @param ownId
	 * @return
	 * @throws DaoException
	 */
	public int update(PriorityConf vo) throws DaoException {
		final String sql = "update " + SI_TABLE("turbo_priority_conf")
				+ " set limit_type=?,begin_value=?,end_value=?,status=?,priority=? where own_id=?";
		String msg = "";
		try {
			return CM.getDao().update("修改权限优先级配置",sql,new Object[] { vo.getLimitType(), vo.getBeginValue(),
							vo.getEndValue(),vo.getStatus(), vo.getPriority(),vo.getOwnId() });
		} catch (DaoException e) {
			msg = "获取权限优先级配置失败";
			logger.error(msg, e);
			throw new DaoException(msg, e);
		}
	}
}
